"use strict";
import { ConfigProvider } from "antd";
import "antd/dist/antd.css";
import zhCN from "antd/lib/locale-provider/zh_CN";
import { get } from "lodash";
import React from "react";
import ReactDOM from "react-dom";
import styles from "./reset.less";
import Routers from "./Routers";

const appDom = document.getElementById("app") as HTMLDivElement;

appDom.classList.add(styles.app, styles.scrollbar);

ReactDOM.render(
    <ConfigProvider locale={zhCN} >
        <Routers />
    </ConfigProvider>,
    appDom
);


if (_DEV_) {
    (module as any)["hot"] && (module as any)["hot"].accept();
}


if (!_DEV_ && "serviceWorker" in navigator) {
    window.addEventListener("load", () => {
        navigator.serviceWorker.register("./service-worker.js").then(registration => {
            var serviceWorker;
            if (registration.installing) {
                serviceWorker = registration.installing;
                console.log('installing')

            } else if (registration.waiting) {
                serviceWorker = registration.waiting;
                console.log('waiting');
            } else if (registration.active) {
                serviceWorker = registration.active;
                console.log('active');
            }
            if (serviceWorker) {
                console.log("serviceWorker.state", serviceWorker.state);
                serviceWorker.addEventListener('statechange', function (e) {
                    console.log('e.target.state', get(e, ['target', 'state']));
                });
            }
        }).catch(registrationError => {
            // console.log("SW registration failed: ", registrationError);
        });
    });
}